package database;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeansException;

import database.dao.PlayerCollectSingerInfoDao;
import database.dao.PlayerCollectSongInfoDao;
import database.pojo.PlayerCollectSongInfo;


import util.JdbcUtils;
import util.MyFactory;

public class PlayerSongDBServer {
	public boolean insertPlayerCollectSong(PlayerCollectSongInfo pInfo) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSongInfoDao", PlayerCollectSongInfoDao.class).insert(pInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	
	public PlayerCollectSongInfo updatePlayerCollectSongInfo(PlayerCollectSongInfo pInfo) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			MyFactory.context.getBean("PlayerCollectSongInfoDao", PlayerCollectSongInfoDao.class).update(pInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
		return pInfo;
	}
	
	public ArrayList<PlayerCollectSongInfo> selectPlayerCollectSongInfoByOpenId(String openId) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSongInfoDao", PlayerCollectSongInfoDao.class).selectAllByOpenId(openId, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	public boolean delect(String openId, String songId) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSongInfoDao", PlayerCollectSongInfoDao.class).delete(openId, songId, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	
	
}